package com.augn.service.impl;

import com.augn.entity.Cooperations;
import com.augn.entity.Goods;
import com.augn.entity.Result;
import com.augn.mapper.CooperationsMapper;
import com.augn.service.ICooperationsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CooperationsServiceImpl extends ServiceImpl<CooperationsMapper, Cooperations> implements ICooperationsService {

    @Autowired
    private CooperationsMapper mapper;

    // 新增一个请求合作对象
    @Override
    public Result<?> insertOneCooperations(Cooperations cooperations) {
        int insert = mapper.insert(cooperations);
        if(insert==0){
            return Result.error("-1","新增失败");
        } else{
            return Result.success(insert);
        }
    }

    //删除一个请求合作对象
    @Override
    public Result<?> deleteOneCooperations(Integer id) {
        int delete = mapper.deleteById(id);
        if(delete==0){
            return Result.error("-1","删除失败");
        } else{
            return Result.success(delete);
        }
    }

    @Override
    public Result<?> getOneCooperations(Integer id) {
        Cooperations cooperations = mapper.selectById(id);
        if(cooperations==null){
            return Result.error("-1","无此商品");
        } else{
            return Result.success(cooperations);
        }
    }

    // 获取请求合作对象列表
    @Override
    public Result<?> getPartCooperations(Integer id) {
        QueryWrapper<Cooperations> wrapper= new QueryWrapper<>();
        wrapper.eq("pro_id",id);
        List<Cooperations> cooperationsList = mapper.selectList(wrapper);
        if(cooperationsList.isEmpty()){
            return Result.error("-1","没有符合此条件的商品");
        } else{
            return Result.success(cooperationsList);
        }
    }
}
